<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>进行药品添加</title>
    <link rel="stylesheet" href="/Trees/LayUiBac/layui/css/layui.css" media="all">
</head>
<body>

<div class="layui-container">
    <div class="layui-row" style="border: cadetblue 1px solid;padding: 20px;margin-top: 30px">
        <div style="border: cadetblue 1px solid;"><h4>点击下方+号进行物品出库准备</h4></div>


        <table id="demo" lay-filter="medicTable"></table>
        <input name="hide" id="hide" type="hidden">
    </div>
</div>
<script src="/Trees/LayUiBac/layui/layui.js"></script>
<script>
    layui.use('table', function () {
        let $ = layui.$;
        let layer = layui.layer;
        let table = layui.table;
        let show = table.render({
            elem: '#demo'
            , url: '/Trees/medic' //数据接口
            , page: false //开启分页
            , toolbar: 'default'
            , parseData: function (res) { //res 即为原始返回的数据
                return {
                    "code": 0, //解析接口状态
                    "count": res.total, //解析数据长度
                    "data": res.list
                };
            }
            , cols: [[ //表头
                {type: 'checkbox', fixed: 'left'}
                , {field: 'pkId', title: 'ID', sort: true, fixed: 'left'}
                , {field: 'name', title: '药品名称'}
                , {field: 'disastertype', title: '防治类型'}
                , {field: 'type', title: '所属类型'}
                , {field: 'purpose', title: '效果'}
            ]]
        });

        table.on('toolbar', function (obj) {
            let str = ""
            let checkStatus = table.checkStatus(obj.config.id)
                , data = checkStatus.data; //获取选中的数据
            switch (obj.event) {
                case 'add':
                    if (data.length === 0) {
                        layer.msg('没有进行选择');
                    } else {
                        layer.msg('添加进了父表格');
                        for (let i = 0; i < data.length; i++) {
                            str += "<tr>" +
                                "<td>" + data[i].pkId + "</td>" +
                                "<td>" + data[i].name + "</td>" +
                                "<td>" + data[i].disastertype + "</td>" +
                                "<td>" + data[i].type + "</td>" +
                                "<td>" + data[i].purpose + "</td>" +
                                "<td contentEditable=true>" + "</td>" +
                                "</tr>"
                        }
                        console.log(str);
                        $('#hide').val(str);
                    }
                    break;
                case 'update':
                    if (data.length === 0) {
                        layer.msg('请选择一行');
                    } else if (data.length > 1) {
                        layer.msg('只能同时编辑一个');
                    } else {
                        layer.alert('编辑 [id]：' + checkStatus.data[0].pkId);
                    }
                    break;
                case 'delete':
                    if (data.length === 0) {
                        layer.msg('请选择一行');
                    } else {
                        layer.msg('删除');
                    }
                    break;
            }

        });

    })
</script>

</body>
</html>